
import { createStore } from 'vuex'
import { login } from '../api'

export const LOGIN = 'login'

export default createStore({
    state: {
        user: null
    },
    mutations: {
        [LOGIN](state, user){
            console.log(user)
            state.user = user
        }
    },
    actions: {
        async [LOGIN](store, user){
            const response = await login(user.username, user.password)
            store.commit(LOGIN, {...response.userInfo, authKey: response.authKey, sessionId: response.sessionId})
        }
    }
})